<?php
namespace app\admin\controller;
use app\admin\controller\Base;
class Bis extends Base
{
     protected $obj;
     public function _initialize() {
         $this->obj=model("Bis");
     }
     //商户列表status=1
     public function index(){
         $bis=$this->obj->getBisByStatus(1);
         return $this->fetch("",[
             "bis"=>$bis,
         ]);
     }
     
     
    //审核表单
    public function apply(){
        $bis=$this->obj->getBisByStatus();
       //
        return $this->fetch("",[
            "bis"=>$bis,
        ]);
    }
    //详情页
    public function detail(){
        $id=input("get.id");
        if(empty($id)){
            $this->error("非法数据");
        }
        $citys=model("City")->getNormalFirstCitys();
        //获取服务类别栏目
        $categorys=model("Category")->getNormalFirstCategorys();
       //获取商户数据
        $bisData=model("Bis")->get($id);
        //获取商户本地数据
       $locationData=model("BisLocation")->get(["bis_id"=>$id,"is_main"=>1]);
      // print_r($locationData);exit();
       $accountData=model("BisAccount")->get(["bis_id"=>$id,"is_main"=>1]); 
        return  $this->fetch('',[
            'citys'=>$citys,
            'categorys'=>$categorys,
            'bisData'=>$bisData,
            'locationData'=>$locationData,
            'accountData'=>$accountData,
        ]);
         
    }
    // 已删除的商户表status=-1
    public function dellist(){
        $bis=$this->obj->getBisByStatus(-1);
        
        return $this->fetch("",[
          "bis"=>$bis,
        ]);
    }
    //修改状态
    public function status(){
       if(!request()->isGet()){
           $this->error("非法请求");
        }
        //get传值
        $data=input("get.");
        //$data["id"]=4;
         $validate=validate("Bis");
         if(!$validate->scene("status")->check($data)){
            $this->error($validate->getError());
        }
        $remail=$this->obj->get(["id"=>$data["id"]]);
        $email=$remail->email;
        //
        $res=$this->obj->save(["status"=>$data['status']],["id"=>$data['id']]);
        $location=model("BisLocation")->save(['status'=>$data['status']],['bis_id'=>$data['id'],"is_main"=>1]);
        $account=model("BisAccount")->save(["status"=>$data['status']],['bis_id'=>$data['id'],"is_main"=>1]);
        if($res && $location && $account){
         //邮件通知对方已审核
        $url=request()->domain().url('bis/register/waiting',['id'=>$data['id']]);
        $title = "o2o入驻申请通知";
        $content="您提交的入驻申请平台方已经审核，您可以通过点击链接<a href='".$url."'   target='_blank'>查看链接</a>审核状态";
         \phpmailer\Email::send($email,$title,$content);
            
            $this->success("更新成功");
        }else{
             $this->error("更新失败");
        }
    }
    
    
    
}
